import { http } from "@/utils/http";
import { useStreamDownload } from "@/utils/useStreamDownload";
export const getCountriesSimple = () => {
  return http.request<any>("get", "/api/user/segment-tree/countries/simple");
};
/** 获取国家列表 */
export const getCountries = () => {
  return http.request<any>("get", "/api/user/segment-tree/countries");
};
//  获取国家下的城市列表
export const getCities = (countryId: string) => {
  return http.request<any>(
    "get",
    `/api/user/segment-tree/countries/${countryId}/cities`
  );
};
// 获取城市下的区号列表
export const getAreaCodes = (cityId: string) => {
  return http.request<any>(
    "get",
    `/api/user/segment-tree/cities/${cityId}/area-codes`
  );
};
// 获取号段列表
export const snRanges = (areaCodeId: string) => {
  return http.request<any>(
    "get",
    `/api/user/segment-tree/area-codes/${areaCodeId}/sn-ranges`
  );
};

// 号码生成预览;
export const getNumberGenerationPreview = (params: {
  countryCode: string;
  cityCode: string;
  areaCode: string;
  segmentCode: string;
  count: number;
}) => {
  return http.request<any>(
    "get",
    "/api/user/segment-tree/number-generation/preview",
    { params }
  );
};

/** 直接下载生成文件(流式) */
export const downloadStream = (params: {
  countryCode: string;
  cityCode: string;
  areaCode: string;
  segmentCode: string;
  count: number;
}) => {
  const { download } = useStreamDownload();
  return download("/api/user/segment-tree/number-generation/download/stream", {
    method: "GET",
    params
  });
};
